package com.tansun.easycare.rule.refemodel.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.github.pagehelper.PageInfo;
import com.tansun.easycare.core.utils.StringUtils;
import com.tansun.easycare.core.web.BaseController;
import com.tansun.easycare.rule.refemodel.entity.RuleReleModel;
import com.tansun.easycare.rule.refemodel.service.RuleReleModelService;

/**
 * 规则引用Controller
 * @author lixs
 * @version 2019-11-19
 */
@Controller
@RequestMapping(value = "/rulerelemodel/ruleReleModel")
public class RuleReleModelController extends BaseController {

	@Autowired
	private RuleReleModelService ruleReleModelService;
	
	@ModelAttribute
	public RuleReleModel get(@RequestParam(required=false) String id) {
		RuleReleModel entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = ruleReleModelService.get(id);
		}
		if (entity == null){
			entity = new RuleReleModel();
		}
		return entity;
	}
	

	@RequestMapping(value = {"list", ""})
	public String list(RuleReleModel ruleReleModel, HttpServletRequest request, HttpServletResponse response, Model model) {
		PageInfo<RuleReleModel> page = ruleReleModelService.findPage(ruleReleModel.getPage(), ruleReleModel); 
		model.addAttribute("page", page);
		return "refemodel/rulerelemodel/ruleReleModelList";
	}


	@RequestMapping(value = "form")
	public String form(RuleReleModel ruleReleModel, Model model) {
		model.addAttribute("ruleReleModel", ruleReleModel);
		return "refemodel/rulerelemodel/ruleReleModelForm";
	}

	@RequestMapping(value = "save")
	public String save(RuleReleModel ruleReleModel, Model model, RedirectAttributes redirectAttributes) {
//		if (!beanValidator(model, ruleReleModel)){
//			return form(ruleReleModel, model);
//		}
		ruleReleModelService.save(ruleReleModel);
		addMessage(redirectAttributes, "保存规则引用成功");
		return "redirect:"+"/rulerelemodel/ruleReleModel/?repage";
	}
	

	@RequestMapping(value = "delete")
	public String delete(RuleReleModel ruleReleModel, RedirectAttributes redirectAttributes) {
		ruleReleModelService.delete(ruleReleModel);
		addMessage(redirectAttributes, "删除规则引用成功");
		return "redirect:"+"/rulerelemodel/ruleReleModel/?repage";
	}

}